package com.example.dllo.baidumusic.main;
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.dllo.baidumusic.R;
import com.example.dllo.baidumusic.bean.SearchBean;

import java.util.List;

/**
 * Created by dllo on 16/9/5.
 */
public class SearchAdapter extends BaseAdapter {
    private Context context;
    private List<SearchBean.ResultBean.SongInfoBean.SongListBean> songListBeen;

    public void setSongListBeen(List<SearchBean.ResultBean.SongInfoBean.SongListBean> songListBeen) {
        this.songListBeen = songListBeen;
        notifyDataSetChanged();
    }

    public SearchAdapter(Context context) {
        this.context = context;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return songListBeen != null ? songListBeen.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return songListBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SearchViewHolder searchViewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.search_item, null);
            searchViewHolder = new SearchViewHolder(convertView);
            convertView.setTag(searchViewHolder);
        } else {
            searchViewHolder = (SearchViewHolder) convertView.getTag();

        }

        searchViewHolder.title.setText(songListBeen.get(position).getTitle());
        searchViewHolder.name.setText(songListBeen.get(position).getAuthor());

        return convertView;
    }

    private class SearchViewHolder {
        private TextView title;
        private TextView name;

        public SearchViewHolder(View view) {
            title = (TextView) view.findViewById(R.id.tv_title);
            name = (TextView) view.findViewById(R.id.tv_name);
        }
    }
}
